Skip to content

Conversation

@chahat-101
Copy link

Fixes #700.

Previously, re-adding an existing peer would return early and ignore an
updated socket address, causing stale peer addresses to be persisted.
This change updates and persists the peer info when the address differs,
and adds a regression test covering the behavior.

@ldk-reviews-bot
Copy link

ldk-reviews-bot commented Dec 30, 2025

I've assigned @tnull as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

@ldk-reviews-bot
Copy link

🔔 1st Reminder

Hey @tnull! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot
Copy link

🔔 2nd Reminder

Hey @tnull! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.


if locked_peers.contains_key(&peer_info.node_id) {
return Ok(());
match locked_peers.get_mut(&peer_info.node_id) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why we bother to first look it up if the following behavior is identical to insert anyways? Why then not just always insert?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense — I missed the inbound-channel case where we shouldn’t overwrite an existing peer address.

pub(crate) fn add_peer(&self, peer_info: PeerInfo) -> Result<(), Error> {
let mut locked_peers = self.peers.write().unwrap();

if locked_peers.contains_key(&peer_info.node_id) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't just drop this, as there are instances where we'd add_peer but don't want to override the peer address if we already have one (e.g., when adding peers for inbound channels in event.rs). To solves this, we should probably just introduce an override: bool flag that lets us not return early. Alternatively, we could have two different methods for updating or inserting a peer.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make sure I implement this the way you expect: would you prefer:

(a) keeping add_peer but adding an explicit override_existing: bool, or

(b) splitting this into two methods (e.g. add_peer_if_missing and upsert_peer)?

I’m happy to update call sites accordingly once I know which behavior you want to be the default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Peer node socketAddress is not updated when passed a new socketAddress

3 participants